import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: true,
		userInfo: uni.getStorageSync('userInfo'),
		schoolInfo: uni.getStorageSync('schoolInfo'),
		carList: [],
		skuIdList: []
	},
	mutations: {
		addToCart(state, carList) {
			// uni.setStorageSync('carInfoVal', carInfoVal);
			state.carList = carList;
		},
		// 更新学校状态
		updateSchoolInfo(state, schoolInfo){
			uni.removeStorage({
				key: 'schoolInfo'
			})
			uni.setStorageSync('schoolInfo', schoolInfo); //缓存用户登陆状态
		},
		// 更新用户信息
		updateUserInfo(state, userInfo) {
			console.log(userInfo,'userInfo');
			state.userInfo = userInfo;
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.setStorageSync('userInfo', userInfo); //缓存用户登陆状态
		},
		login(state, provider) {
			// state.hasLogin = uni.setStorageSync('hasLogin', true);
			state.userInfo = provider;
			uni.setStorageSync('userInfo', provider); //缓存用户登陆状态
			uni.setStorageSync('clinetToken', provider.token);
			console.log(state.userInfo);
		},
		logout(state) {
			// state.hasLogin = false;
			state.userInfo = {};
			// uni.removeStorage({
			// 	key: 'hasLogin'
			// })
			uni.removeStorage({
				key: 'userInfo'
			})
			uni.removeStorage({
				key: 'clinetToken'
			})
		}
	},
	actions: {

	}
})

export default store